<!DOCTYPE HTML>
<html>
<HEAD>
<meta charset="UTF-8">
<script type="text/javascript" src="js/jquery-1.3.2.js"></script> 
<script type="text/javascript" src="js/jquery.date_input.js"></script> 
<link rel="stylesheet" href="js/date_input.css" type="text/css">

<script>
//日期插件
jQuery.extend(DateInput.DEFAULT_OPTS, { 
month_names: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], 
short_month_names: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"], 
short_day_names: ["一", "二", "三", "四", "五", "六", "日"],
 dateToString: function(date) {
    var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    return date.getFullYear() + "-" + month + "-" + dom;
  }

}); 



$(function() { 
$(".biuuu1").date_input(); 
$(".biuuu2").date_input(); 
}); 
</script>

<TITLE>添加消息回复</TITLE>
</HEAD>



<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//上传文件类型列表  
$uptypes=array(  
    'image/jpg',  
    'image/jpeg',  
    'image/png',  
    'image/pjpeg',  
    'image/gif',  
    'image/bmp',  
    'image/x-png'  
);  
  
$max_file_size=2000000;     //上传文件大小限制, 单位BYTE  
$destination_folder="/data/wechat/public_html/upload/img/"; //上传文件路径  


if(isset($_POST['submit'])){
    //var_dump($_FILES);
    
    $file = $_FILES["upfile"];  
    //图片文件链接
    $picFileName = "";
    if (!is_uploaded_file($_FILES["upfile"]["tmp_name"]))  
    //是否存在文件  
    {  
         echo "图片不存在，文件上传失败!";  
        // exit;  
    }     //检查文件大小  
   if($max_file_size < $file["size"]) 
    {  
        echo "<script>alert('文件太大!');</script>";  
        //exit;  
     } 
     if(!in_array($file["type"], $uptypes))  
    //检查文件类型  
    {  
        echo "<script>alert('文件类型不符!');</script>".$file["type"];  
        //exit;  
    }  
    if(!file_exists($destination_folder))  
    {  
        if(mkdir($destination_folder)){
            echo "<script>alert('成功创建文件夹');</script>";  
        }else{
            echo "<script>alert('创建文件夹失败');</script>";  
            //exit;  
        }
    }  
    
    $filename=$file["tmp_name"];  
    $image_size = getimagesize($filename);  
    $pinfo=pathinfo($file["name"]);  
    $ftype=$pinfo['extension'];  
    $destination = $destination_folder.time().".".$ftype;  
    
    if (file_exists($destination) && $overwrite != true)  
    {  
        echo "<script>alert('同名文件已经存在了');</script>";  
      //  exit;  
    }  
  
    if(!move_uploaded_file ($filename, $destination))  
    {  
        echo "<script>alert('移动文件出错');</script>";  
        //exit;  
    }  
 
    //保存图片文件的链接地址
    $picFileName = "http://wechat.zhijia365.com/upload/img/".time().".".$ftype;
      
    //关于图片链接的操作结束，图片文件链接为 $picFileName
   
    //编辑时间
    //进行连接数据库操作
    include_once('../DB.php');
    $DB =  new DB();
   
    $editTime = time();
    echo $editTime."<br>";
    $replydata = array('reply_key'=>$_POST['key'],'reply_value'=>$_POST['value'],'pic'=>$picFileName,
        'link'=>$_POST['link'],'addTime'=>strtotime($_POST['addTime']),'editTime'=>$editTime,
            'endTime'=> strtotime($_POST['endTime']),'re_status'=>$_POST['status'],'type'=>$_POST['type']);
    
    foreach($replydata as $color)
    echo $color;
   
     //获取操作信息,如果是进行了更新操作
    if($_GET["action"]){
    $action=$_GET["action"];
     //获取ID号
    $id=intval($_GET["id"]);
    $bool = $DB->update("reply",$replydata,"id ={$id}"); 
    if($bool){
         echo "<script>alert('数据更新操作成功！');location='reply_list.php';</Script>";
        }
    }
    //说明不是更新操作，是增加操作
    else{
         
     $bool = $DB->insert("reply",$replydata); 
     if($bool){
         echo "<script>alert('数据添加操作成功！');location='reply_list.php';</Script>";
         }
     }
   
    }
      
        
?>
<b>添加消息回复</b>
   <form action=""enctype="multipart/form-data" method="post"  name="upform">
       关键字:<input type="text" name="key"></br>
       回复内容：<input type="text" name="value"></br>
       回复图片：    
       <input name="upfile" type="file" >允许上传的文件类型为:<?=implode(', ',$uptypes)?></br> 
       回复链接：<input type="text" name="link" ></br>
       回复添加时间：<input type="text" class="biuuu1"name="addTime" ></br>
       回复结束时间：<input type="text" class="biuuu2" name="endTime" ></br>
       回复状态：<select name="status">  
                <option value ="1">1</option>  
                 <option value ="2">2</option>  
                </select>ps:1是回复应用状态，2是回复未启用</br>
       回复类型：<select name="type">  
                <option value ="1">1</option>  
                 <option value ="2">2</option>  
                <option value="3">3</option>  
                <option value="4">4</option>  
                </select>ps:1是文本类型，2是图文类型,3是音乐类型，4是链接类型回复</br>
       <input type="submit" name="submit" value="提交"> 
   </form>
